package com.scoutmobmap.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.scoutmobmap.shared.GreetRequest;
import com.scoutmobmap.shared.GreetResponse;
import com.scoutmobmap.shared.GreetingService;
import com.scoutmobmap.shared.GreetingServiceAsync;

public class ScoutmobViewer implements EntryPoint {
  private static GreetingServiceAsync greetService = GWT.create(GreetingService.class);

	public void onModuleLoad() {
	  final RootLayoutPanel rp = RootLayoutPanel.get();
	  
    DockLayoutPanel dock = new DockLayoutPanel(Unit.PX);
    
    SimplePanel header = new SimplePanel();
    header.add(new HTML("<h1> Header </h1>"));
    dock.addNorth(header, 75);
    
    final ListPanel listPanel= new ListPanel();
    final MapPanel mapPanel = new MapPanel();
    dock.addWest(listPanel, 300);
    dock.add(mapPanel);
    
    greetService.greetServer(new GreetRequest(), new AsyncCallback<GreetResponse>() {
      @Override public void onFailure(Throwable caught) { Window.alert("Server Failure"); }
      @Override public void onSuccess(GreetResponse result) {
        listPanel.initializeData(result.offers);
        mapPanel.initializeData(result.offers);        
      }
    });
    rp.add(dock);
	}
}
